home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-08-08 | 1.3 KB | 34 lines | [TEXT/EDIT] |
- ; This is a translation into Scheme of a graphics example that
- ; Apple distributes with the Smalltalk-80 programming system.
- ; (mandala x0 y0 r n) draws a mandala of radius r, centered at <x0, y0>,
- ; with n equally spaced vertices. A picture is worth a thousand words;
- ; try:
- ; (mandala 235 130 130 30)
- ;
- ; A graphics window must be open when this procedure is called.
-
- (define (mandala x0 y0 radius npoints)
- (move-to (+ x0 radius) y0)
- (do ((x (make-vector npoints))
- (y (make-vector npoints))
- (i (-1+ npoints) (-1+ i))
- (delta (/ (* 2 3.14159265) npoints))
- (theta 0.0 (+ theta delta))
- (x0 (* 1.0 x0))
- (y0 (* 1.0 y0))
- (radius (* 1.0 radius)))
- ((negative? i)
- (line-to (vector-ref x (- npoints 1))
- (vector-ref y (- npoints 1)))
- (do ((i (- (quotient npoints 2) 1) (- i 1)))
- ((negative? i))
- (do ((j 0 (+ j 1)))
- ((=? j npoints))
- (move-to (vector-ref x j) (vector-ref y j))
- (line-to
- (vector-ref x (remainder (+ j i) npoints))
- (vector-ref y (remainder (+ j i) npoints))))))
- (vector-set! x i (round (+ x0 (* radius (cos theta)))))
- (vector-set! y i (round (+ y0 (* radius (sin theta)))))
- (line-to (vector-ref x i) (vector-ref y i))))
-